import express from 'express';
import controller from './controller';
import multer from 'multer';

// 定义DiskStorage对象
const storage = multer.diskStorage({
    // 对存储路径进行配置
    destination: function(_req, _file, callback) {
        callback(null, 'upload/images/')
    },
    // 对文件名进行配置
    filename: function(_req, file, callback) {
        callback(null, Date.now()  + "." + file.originalname.split('.').pop())
    }
})
// 定义Multer对象
const upload = multer({    
    storage: storage
})
  
export default express
  .Router()
  .post('/image/upload', upload.single('file'), controller.upload)